<template>
  <div style="padding:15px;">
    <vxe-toolbar id="toolbarId" :setting="{storage: true}" export :refresh="{query: findList}">
      <template v-slot:buttons>
        <el-button @click="findList">查询</el-button>
        <!-- <el-button @click="funcAdd">新增</el-button> -->
        <el-date-picker
          v-model="listQuery.reptdtStart"
          type="date"
          placeholder="开始日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          style="width: 140px;"
        />
        <el-date-picker
          v-model="listQuery.reptdtEnd"
          type="date"
          placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          style="width: 140px;"
        />
      </template>
    </vxe-toolbar>
    <vxe-table
      ref="xTable"
      resizable
      border
      :show-footer="true"
      :footer-method="footerMethod"
      :loading="loading"
      highlight-current-row
      highlight-hover-row
      row-id="id"
      class="mytable-footer"
      height="700"
      :data="tableData"
      remote-sort
      @sort-change="sortList"
    >
      <vxe-table-column>
        <vxe-table-column
          field="createMonth"
          title="月份"
          show-header-overflow
          show-overflow
          min-width="100"
          sortable
        />
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="userName"
          title="客户名称"
          show-header-overflow
          show-overflow
          min-width="100"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.userName" placeholder="请输入客户名称" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="userPhone"
          title="手机号码"
          show-header-overflow
          show-overflow
          min-width="140"
          sortable
        />
        <template v-slot:header="{ column }">
          <el-input v-model="listQuery.userPhone" placeholder="请输入手机号码" clearable />
        </template>
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="startBalance"
          title="期初余额"
          show-header-overflow
          show-overflow
          min-width="100"
          sortable
        />
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="shouldBalance"
          title="应收金额"
          show-header-overflow
          show-overflow
          min-width="100"
          sortable
        />
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="alreadyBalance"
          title="已收金额"
          show-header-overflow
          show-overflow
          min-width="100"
          sortable
        />
      </vxe-table-column>
      <vxe-table-column>
        <vxe-table-column
          field="endBalance"
          title="未收金额"
          show-header-overflow
          show-overflow
          min-width="100"
          sortable
        />
      </vxe-table-column>
    </vxe-table>
    <vxe-pager
      :loading="loading"
      :current-page.sync="listQuery.pageNum"
      :page-size.sync="listQuery.pageSize"
      :total="listQuery.total"
      :layouts="['PrevJump', 'PrevPage', 'Number', 'NextPage', 'NextJump', 'Sizes', 'FullJump', 'Total']"
      @page-change="handlePageChange"
    />
  </div>
</template>
<script>
import Vue from "vue";
import "xe-utils";
import VXETable from "vxe-table";
import "vxe-table/lib/index.css";
import XEUtils from "xe-utils";
import VXEUtils from "vxe-utils";
Vue.use(VXETable, VXEUtils, XEUtils, {
  mounts: ["cookie"]
});
import request from "@/utils/request";
export default {
  name: "PartyList",
  components: {},
  data() {
    return {
      message: "",
      loading: false,
      tableData: [],
      copy: false,
      alreadyBalance: "",
      shouldBalance: "",
      listQuery: {
        code: "", // code编码
        userCode: "", // 用户编码(入驻商或司机)
        userName: "", // 客户名称
        userPhone: "", // 客户电话
        reptdt: "", // 统计时间
        reptdtStart: "", // 统计时间开始
        reptdtEnd: "", // 统计时间结束
        startBalance: "", // 期初余额
        shouldBalance: "", // 应收金额或应付金额
        alreadyBalance: "", // 已收金额或已付金额
        endBalance: "", // 期末余额
        type: 0, // 0 应收 1应付
        pageNum: 1,
        pageSize: 10,
        sortField: "",
        sortType: "",
        total: 0
      },
      roleList: []
    };
  },
  created() {
    this.findList();
  },
  methods: {
    findList() {
      this.loading = true;
      return new Promise(resolve => {
        request({
          url: "ntocc-tms-api/statistics/getSumReceiveLedgerList",
          method: "get",
          params: this.listQuery
        }).then(response => {
          this.tableData = response.data.records;
          this.listQuery.total = response.data.total;
          this.shouldBalance = response.data.sumObject.shouldBalance;
          this.alreadyBalance = response.data.sumObject.alreadyBalance;
          this.loading = false;
          resolve();
        });
      });
    },
    // 排序
    sortList({ column, property, order }) {
      if (order) {
        this.listQuery.sortField = property;
        this.listQuery.sortType = order;
      } else {
        this.listQuery.sortField = "";
      }
      this.findList();
    },
    // 分页handle
    handlePageChange({ currentPage, pageSize }) {
      this.listQuery.pageNum = currentPage;
      this.listQuery.pageSize = pageSize;
      this.findList();
    },
    // 底部颜色设置
    /*     footerCellClassName({ $rowIndex, column, columnIndex }) {
      if (columnIndex === 0) {
        if ($rowIndex === 0) {
          return 'col-blue'
        } else {
          return 'col-red'
        }
      }
    }, */
    // 设置底部合计
    footerMethod({ columns, data }) {
      return [
        columns.map((column, columnIndex) => {
          if (columnIndex === 0) {
            return "合计";
          }
          if (column.property === "shouldBalance") {
            // 冻结金额
            return this.shouldBalance;
          }
          if (column.property === "alreadyBalance") {
            // 账户金额
            return this.alreadyBalance;
          }
          if (["pageviews", "forecast"].includes(column.property)) {
            return XEUtils.sum(data, column.property);
          }
          return null;
        })
      ];
    }
  }
};
</script>
<style>
.vxe-table .vxe-body--column:not(.col--ellipsis),
.vxe-table .vxe-footer--column:not(.col--ellipsis),
.vxe-table .vxe-header--column:not(.col--ellipsis) {
  padding: 6px 0;
}
.vxe-toolbar {
  padding: 0 0 10px 0;
}
</style>
